package com.woniuxy.carlife.controller;


import com.alibaba.fastjson.JSON;
import com.woniuxy.carlife.carlifecommonsweb.responsetemplate.Result;
import com.woniuxy.carlife.carlifecommonsweb.responsetemplate.StatusCode;
import com.woniuxy.carlife.domain.StoreTags;
import com.woniuxy.carlife.service.StoreTagsService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName:  StoreTagsController
 *@Description: 门店服务标签选择前端控制器
 * @author: yanzhongliang     
 * @date: 2021-04-05
 */

@RestController
@Slf4j
@Api(tags = "门店服务标签选择接口信息（注册选择用）")//用于描述接口类的相关信息，作用于类上
@RequestMapping("/store-tags")
public class StoreTagsController {
    @Resource
    private StoreTagsService storeTagsService;
    @Resource
    private RedisTemplate redisTemplate;
    /**
     * 功能描述〈查询所有门店服务标签〉
     * @author: yanzhongliang
     * @param: null
     * @return: List<StoreTags>
     * @Date 2021/4/7 16:57
     * @throws
     */

    //@ApiOperation用于描述接口方法，作用于方法上
    @ApiOperation(value = "查询所有门店标签",notes = "<span style='color:red;'>用来注册时选择门店服务标签展示的接口</span>")
    //@ApiResponses用于描述响应状态信息
    @ApiResponses({
            @ApiResponse(code = 40012,message = "查询成功",response = StoreTags.class),
            @ApiResponse(code=40011,message = "查询为空")
    })

    @GetMapping("/merchantmanage/storeTagsfindList")
    public Result getStoreTagsfindList(){

        log.info("开始查询门店服务选择标签");
        //查询到所有可供选择的门店服务标签
        List<StoreTags> list=storeTagsService.getStoreTagsfindList();
        if (!list.isEmpty()){
            log.info("查询到所有门店服务标签名集合：参数：{}",list);
            //将查询到的门店详情转成json字符串
            String strJson= JSON.toJSONString(list);
            // 存入redis
            redisTemplate.opsForHash().put("store","tagsName",strJson);
            //返回服务标签名集合
            return new Result(true, StatusCode.SEARCH_SUCCESSFUL,"查询所有门店服务选择标签成功",list);
        }else {
            return new Result(false, StatusCode.QUERY_IS_EMPTY,"查询为空");
        }

    }

}

